package com.solarroast.mirrorarray.components;

import java.awt.Color;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.JButton;

public class Mirror {
	private float initLocHor;
	private float initLocVert;
	private float currLocHor;
	private float currLocVert;
	private float targetLocHor;
	private float targetLocVert;
	private boolean active;
	private Random rGen = new Random();
	private JButton mirrorBut;
	private String name;
	private MirrorArrayItem mirrorArrayItem;
	
	public Mirror(String name, MirrorArrayItem mAItem) {
		if(rGen.nextInt() % 2 == 0 ? (active = true) : (active = false));
		this.mirrorArrayItem = mAItem;
		this.name = name;
		mirrorBut = new JButton(name);
		mirrorBut.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				if(active) {
					active = false;
					mirrorBut.setForeground(Color.RED);
				}
				else {
					active = true;
					mirrorBut.setForeground(Color.GREEN);
				}
				
				mirrorArrayItem.recalculateColor();
			}
		});
		
		if(active)
			mirrorBut.setForeground(Color.GREEN);
		else
			mirrorBut.setForeground(Color.RED);
	}
	
	public boolean getActive() {
		return active;
	}
	
	public void setActive(boolean active) {
		this.active = active;
		
		if(active)
			mirrorBut.setForeground(Color.GREEN);
		else
			mirrorBut.setForeground(Color.RED);
	}
	
	public float getInitLocHor() {
		return initLocHor;
	}
	
	public void setInitLocHor(float initLocHor) {
		this.initLocHor = initLocHor;
	}
	
	public float getInitLocVert() {
		return initLocVert;
	}
	
	public void setInitLocVert(float initLocVert) {
		this.initLocVert = initLocVert;
	}
	
	public float getCurrLocHor() {
		return currLocHor;
	}
	
	public void setCurrLocHor(float currLocHor) {
		this.currLocHor = currLocHor;
	}
	
	public float getCurrLocVert() {
		return currLocVert;
	}
	
	public void setCurrLocVert(float currLocVert) {
		this.currLocVert = currLocVert;
	}
	
	public float getTargetLocHor() {
		return targetLocHor;
	}
	
	public void setTargetLocHor(float targetLocHor) {
		this.targetLocHor = targetLocHor;
	}
	
	public float getTargetLocVert() {
		return targetLocVert;
	}
	
	public void setTargetLocVert(float targetLocVert) {
		this.targetLocVert = targetLocVert;
	}
	
	public JButton getButton() {
		return mirrorBut;
	}
}
